/**
  ******************************************************************************
  * @file    SCK_IsRxDataReady2.c
  * @author  exatron
  * @version V1.0.0
  * @date    segunda, 22 de dezembro de 2014
  * @brief   FIFO de socket que possuem dados a ler.
  ******************************************************************************
  * @attention
  *
  *
  ******************************************************************************
  */

/**
  * @addtogroup SCK
  * @{
  */

/* Includes ------------------------------------------------------------------*/
#include <common.h>

extern Socket_t sock[N_SOCKS];
extern FIFO_t isrx_fifo;

/* External functions --------------------------------------------------------*/

/**
  * @defgroup SCK_Functions
  * @{
  */

/**
  * @brief  FIFO de socket que possuem dados a ler.
  * @param  SocketID_t: Socket a fechar
  * @retval Devolve pela serial Result_t
  */
void SCK_IsRxDataReady2(void)
{
	#ifdef DEBUG
	debug_append("%s - %s", __FUNCTION__, "enter");
	#endif

	int nr=0, temp_id, i=0;
	char isrx_buf[N_SOCKS];

	nr = fifo_read(&isrx_fifo, isrx_buf, N_SOCKS);

	for(i=0; i<nr; i++)
	{
		temp_id = isrx_buf[i];
		if(sock[temp_id].status == Status_SocketConnected)
			fifo_write(&isrx_fifo, &temp_id, 1);
	}

	nr = fifo_read(&isrx_fifo, isrx_buf, N_SOCKS);

	if(nr == 0)
		aux_USART0_puts("SCK_IRDR2=%d\r\n", Result_Error);
	else
	{
		fifo_write(&isrx_fifo, isrx_buf, nr);
		aux_USART0_puts("SCK_IRDR2=%d\r\n", isrx_buf[0]);
	}

	aux_SetBusy(FALSE);

	#ifdef DEBUG
	debug_append("%s - %s", __FUNCTION__, "exit");
	#endif
}

/**
  * @}
  */

/**
  * @}
  */





